<?php
    require_once 'controls/global_frontend.php';
    $login_user = new user_controller();
if (isset($_POST['btn_submit'])) {
    $_username = $_POST['username'];
    $_password = $_POST['password'];
    $_ck_remember = 'check';
    $login_user->user_login($_username, $_password , $_ck_remember);
    $_SESSION['log'] = 'log';
}
if( isset($_COOKIE["username"]) && isset($_COOKIE["password"]) && $_COOKIE["password"] != "out" && $_COOKIE["username"] != "log"){
    //exit;
    $_username = $_COOKIE["username"];
    $_password = $_COOKIE["password"];
    $_ck_remember = "check";
    $login_user->user_login($_username, $_password, $_ck_remember);
}

if(isset($_SESSION['user'])){
if (($_SESSION['user']->username != "")) {
    $_SESSION['action'] = '';
    $_SESSION['log'] = 'ok';
     header("Location:index.php?action=login");
     }
}
if(isset($_SESSION['log']) && $_SESSION['log']=='log') $display = ''; else $display = 'style="display:none;"';
?>
<div  <?php echo $display; ?> id="bg-login" >   </div>
<div id="login_popup" <?php echo $display; ?> >

                               <form  action="" method="POST">
                                            <table border="0" cellpadding="0" cellspacing="0" >     
                                                <tr>
                                        			<th>Username</th>
                                        			<td><input type="text" name="username"  /></td>
                                                </tr>
                                                <tr>
                                                    <th>Password</th>
                                        			<td><input type="password" name="password"  onfocus="this.value=''" /></td>
                                                </tr>
                                                <tr id="notice">
                                                    <td colspan="3" >
                                                        <span style="color:red;font:normal 12px tahoma;">Your login is invalid. Please try again.</span>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td><input style="float: right;" type="checkbox" name="ck_remember" value="check" class="checkbox-size" id="login-check" /></td>
                                                    <td style="font:bold 12px Tahoma;"><span style="margin-left:5px;">Remember</span><span>me</span></td> 
                                                </tr>
                                                <tr>
                                                     <td><input type="submit" name="btn_submit" value="Login" class="login_button" /></td>
                                                      <td><input type="button" name="btn_cancel" value="Cancel" class="login_button" onclick="$('#login_popup').fadeOut();$('#bg-login').fadeOut();"/></td>
                                                </tr>
                                                
                                            </table>
                                            <!-- end id-form    -->   
                            </form>      
    
</div>